/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Perhatian;

/**
 *
 * @author Florencia
 */
public class PerhatianTableModel extends AbstractTableModel {

    private List<Perhatian> perhati = new ArrayList<Perhatian>();

    public PerhatianTableModel(List<Perhatian> perhatian) {
        this.perhati = perhatian;
    }

    public void deletePerhatian(int row) {
        perhati.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updatePerhatian(int row, Perhatian perhatian) {
        perhati.set(row, perhatian);
        fireTableRowsUpdated(row, row);
    }

    public void addPerhatian(Perhatian perhatian) {
        perhati.add(perhatian);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    public int getRowCount() {
        return perhati.size();
    }

    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Perhatian b = perhati.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getIdPerhatian();
            case 1:
                return b.getNamaPerhatian();
            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID PERHATIAN";
            case 1:
                return "NAMA PERHATIAN";
            default:
                return "";
        }
    }
}
